/**
 *	    1、projectname变量开发是不需要存在，npm run serve可以不带参数，启动所有模块，
 *		我们希望实现projectA、projectB分别打包于是执行命令：
 *		npm run build user
 *		npm run build products
 */
var glob = require("glob");
var projectname = process.argv[3];

function getEntry() {
	//函数内部var自动具有作用域
	var entries = {};
	if (process.env.NODE_ENV == "production") {
		entries = {
			index: {
				// page的入口
				entry: "src/modules/" + projectname + "/main.ts",
				// 模板来源
				template: "public/index.html",
				// 在 dist/index.html 的输出
				filename: "index.html",
				//index.html title
				title: projectname,
				//chunks
				chunks: ["chunk-vendors", "chunk-common", "index"],
			}
		};
	} else {
		var items = glob.sync("./src/modules/*/*.ts");
		for (var i in items) {
			var filepath = items[i];
			var fileList = filepath.split("/");
			var fileName = fileList[fileList.length - 2];
			entries[fileName] = {
				entry: `src/modules/${fileName}/main.ts`,
				// 模板来源
				template: `public/index.html`,
				// 在 dist/index.html 的输出
				filename: `${fileName}.html`,
				// 提取出来的通用 chunk 和 vendor chunk。
				title: fileName,
				//chunks
				chunks: ["chunk-vendors", "chunk-common", fileName],
			};
		}
	}
	return entries;
}
var pages = getEntry();

module.exports = {
	productionSourceMap: false,
  	outputDir: "dist/" + projectname,
  	pages: pages,
	lintOnSave:false,
	publicPath: process.env.NODE_ENV === 'production' ? './' : '/'
};
